<app-configuration-assessment-result-printable-report
  #testResult
  *ngIf="isPrinting"
  class="printable-area"
  [testResult]="configTestResult">
</app-configuration-assessment-result-printable-report>
<div class="nv-dialog screen-area">
  <div
    class="d-flex justify-content-between align-items-center"
    *ngIf="source === navSource['SELF']">
    <div class="">
      <h1 class="font-weight-light mb-0" id="admissionControlTitle">
        {{ 'sidebar.nav.ADMISSION_CONTROL' | translate }}
      </h1>
    </div>
    <div class="d-flex justify-content-end align-items-center">
      <div *ngIf="source === navSource['SELF']" class="">
        <button
          mat-raised-button
          aria-label="Configuration Assessment"
          color="primary"
          class="policy-top-button"
          *appDisplayControl="'write_admission'"
          (click)="openConfigAssessmentDialog()">
          <em class="eos-icons icon-18 mr-1">flask</em>
          {{ 'admissionControl.MATCHING_TEST' | translate }}
        </button>
      </div>
      <div class="" *appDisplayControl="'write_admission'">
        <div *ngIf="source === navSource['SELF']">
          <button mat-button [matMenuTriggerFor]="menu">
            {{ 'admissionControl.MORE' | translate }}
            <em class="eos-icons">arrow_drop_down</em>
          </button>
          <mat-menu #menu="matMenu">
            <div class="menu-width-medium">
              <button
                mat-menu-item
                class="d-flex align-items-center"
                (click)="showAdvancedSetting()"
                *ngIf="globalStatus">
                <em class="eos-icons mr-2">config_map</em>
                {{ 'admissionControl.GLOBAL_OPS' | translate }}
              </button>
            </div>
            <div class="menu-width-medium">
              <button
                mat-menu-item
                class="d-flex align-items-center"
                (click)="openExportPopup()">
                <em class="eos-icons mr-2">download</em>
                {{ 'admissionControl.EXPORT' | translate }}
              </button>
            </div>
            <button
              mat-menu-item
              class="d-flex align-items-center"
              (click)="openImportPopup()">
              <em class="eos-icons mr-2">upload</em>
              {{ 'admissionControl.IMPORT' | translate }}
            </button>
          </mat-menu>
        </div>
      </div>

      <ng-container *ngIf="source === navSource['SELF']">
        <app-loading-button
          (btnClick)="refresh()"
          [disabled]="!!(refreshing$ | async)"
          [appearance]="'mat-button'"
          [buttonClasses]="'d-flex justify-content-center align-items-center'"
          [iconClasses]="'eos-icons icon-18'"
          [iconName]="'refresh'"
          [id]="'admission-control-refresh-button'"
          [loading]="!!(refreshing$ | async)"
          [text]="'network.REFRESH' | translate"
          [type]="'button'">
        </app-loading-button>
      </ng-container>
    </div>
  </div>

  <div
    [ngClass]="{
      panel: source === navSource['SELF'],
      mb0: source === navSource['SELF']
    }">
    <div [ngClass]="{ 'panel-body': source === navSource['SELF'] }">
      <div class="d-flex justify-content-between align-items-center">
        <div class="d-flex justify-content-start align-items-center">
          <span class="mr-2">
            <span *ngIf="filtered">
              {{ 'enum.FOUND' | translate }}
              {{ filteredCount }}&nbsp;/&nbsp;
            </span>
            {{ admissionRules.length }}
            {{ 'policy.COUNT_POSTFIX' | translate }}
          </span>
          <button
            mat-stroked-button
            aria-label="Add rule"
            *appDisplayControl="'write_admission'"
            (click)="openAddEditAdmissionRuleModal()">
            <em class="eos-icons icon-18">add</em>
            {{ 'admissionControl.INSERT' | translate }}
          </button>
          <div
            *ngIf="
              isMaster &&
              selectedAdmissionRules &&
              selectedAdmissionRules.length > 0 &&
              !hasSelectedDefaultRule
            "
            class="ml-2">
            <button
              mat-stroked-button
              aria-label="prompt rule"
              *appDisplayControl="'multi_cluster'"
              (click)="promoteRule()">
              <em class="eos-icons icon-18">navigation</em>
              {{ 'policy.PROMOTE' | translate }}
            </button>
          </div>
        </div>
        <div class="d-flex justify-content-end align-items-center">
          <div
            class="d-flex align-items-center"
            *ngIf="
              globalStatus &&
              isAdmissionRuleAuthorized &&
              source === navSource['SELF']
            ">
            <label class="nv-modal-item-title margin-right-m mb-0">
              {{ 'admissionControl.MODE' | translate }}
            </label>
            <mat-button-toggle-group
              name="switchMode"
              aria-label="switch mode"
              [disabled]="!isWriteAdmissionRuleAuthorized"
              [(ngModel)]="mode"
              (change)="toggleMode()">
              <mat-button-toggle value="monitor">{{
                'enum.MONITOR' | translate
              }}</mat-button-toggle>
              <mat-button-toggle value="protect">{{
                'enum.PROTECT' | translate
              }}</mat-button-toggle>
            </mat-button-toggle-group>
          </div>
          <div
            class="mx-3 d-flex align-items-center"
            *ngIf="source === navSource['SELF']">
            <label class="nv-modal-item-title margin-right-s mb-0">
              {{ 'responsePolicy.gridHeader.STATUS' | translate }}
            </label>
            <mat-slide-toggle
              [matTooltip]="stateWarning"
              [matTooltipDisabled]="canConfig && isK8s && !admissionStateErr"
              matTooltipClass="tooltip-error"
              id="status-toggle"
              *appDisplayControl="'admission'"
              [disabled]="
                !canConfig ||
                !isK8s ||
                admissionStateErr ||
                !isWriteAdmissionRuleAuthorized
              "
              [(ngModel)]="globalStatus"
              (change)="toggleStatus()">
              <span
                [ngClass]="{
                  'text-muted': !globalStatus,
                  'text-success': globalStatus
                }">
                {{
                  (globalStatus
                    ? 'policy.status.ENABLED'
                    : 'policy.status.DISABLED'
                  ) | translate
                }}
              </span>
            </mat-slide-toggle>
          </div>
          <app-quick-filter
            (filterCountChange)="filterCountChanged($event)"
            [gridOptions]="gridOptions"
            [showCount]="false">
          </app-quick-filter>
          <ng-container *ngIf="source === navSource['FED_POLICY']">
            <app-loading-button
              *ngIf="source !== navSource['SELF']"
              (btnClick)="refresh()"
              [appearance]="'mat-button'"
              [buttonClasses]="
                'd-flex justify-content-center align-items-center'
              "
              [iconClasses]="'eos-icons icon-18'"
              [iconName]="'refresh'"
              [id]="'fed-adm-refresh-button'"
              [text]="'network.REFRESH' | translate"
              [type]="'button'">
            </app-loading-button>
          </ng-container>
        </div>
      </div>

      <ag-grid-angular
        id="admission-rule-grid"
        style="width: 100%"
        [ngStyle]="{ height: gridHeight + 'px' }"
        class="ag-theme-balham"
        [gridOptions]="gridOptions"
        [rowData]="admissionRules"
        [enableCellTextSelection]="true"
        [ensureDomOrder]="true"
        [context]="context">
      </ag-grid-angular>
    </div>
  </div>
</div>
